<template>
  <div id="app">
    <Splash v-if="show" />
    <!-- <keep-alive> -->
      <router-view />
    <!-- </keep-alive> -->
    <TabBar v-if="tabBarShow" />
  </div>
</template>

<script>
import TabBar from "./components/TabBar/TabBar";
import Splash from "./components/Splash/Splash";

export default {
  name: "App",
  components: {
    TabBar,
    Splash
  },
  data() {
    return {
      show: false,
      tabBarShow: true,
      tabBarUrlPaths: ["/home", "/menu", "/owner", "/order", "/cart", "/", " "]
    };
  },
  mounted() {
    this.loadSplash(4000);
    this.detectCurrentUrl();
    this.getViewHeight()
    this.$router.push("/home");
  },
  methods: {
    loadSplash: function(time) {
      var that = this;
      that.show = true;
      setTimeout(function() {
        that.show = false;
      }, time);
    },
    /**
     * 退出重新进应用，检测当前路由是否显示tabBar
     */
    detectCurrentUrl() {
      let path = this.$route.path;
      this.tabBarShow = !this.tabBarUrlPaths.includes(path) ? false : true;
    },
    getViewHeight() {
      let app = document.querySelector("#app");
      app.style.height = document.body.clientHeight + "px";
    }
  },
  watch: {
    $route(to, from) {
      console.log("app:", from);
      this.tabBarShow = !this.tabBarUrlPaths.includes(to.path) ? false : true;
    }
  }
};
</script>

<style lang="less">
#app {
  font-family: Microsoft YaHei, Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
html,
body,
#app {
  background-color: #efefef;
  overflow: hidden;
  height: 100%;
}
::-webkit-scrollbar {
  display: none;
}
.splash-enter {
  opacity: 1;
}
.splash-leave {
  opacity: 0;
}
.splash-enter-active.splash-leave-active {
  transition: opacity 2s ease;
}
</style>
